package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.TCompanyDept;
import com.ruoyi.system.service.ITCompanyDeptService;

import ch.qos.logback.classic.Logger;

import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 企业部门管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-02-13
 */
@Controller
@RequestMapping("/system/tCompanyDept")
public class TCompanyDeptController extends BaseController
{
    private String prefix = "system/tCompanyDept";
	
	@Autowired
	private ITCompanyDeptService tCompanyDeptService;
	
	@RequiresPermissions("system:tCompanyDept:view")
	@GetMapping()
	public String tCompanyDept()
	{
	    return prefix + "/tCompanyDept";
	}
	
	/**
	 * 查询企业部门管理列表
	 */
	@RequiresPermissions("system:tCompanyDept:list")
	@GetMapping("/list")
	@ResponseBody
	public List<TCompanyDept> list(TCompanyDept tCompanyDept)
	{
        List<TCompanyDept> list = tCompanyDeptService.selectTCompanyDeptList(tCompanyDept);
		return list;
	}
	
	
	/**
	 * 导出企业部门管理列表
	 */
	@RequiresPermissions("system:tCompanyDept:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TCompanyDept tCompanyDept)
    {
    	List<TCompanyDept> list = tCompanyDeptService.selectTCompanyDeptList(tCompanyDept);
        ExcelUtil<TCompanyDept> util = new ExcelUtil<TCompanyDept>(TCompanyDept.class);
        return util.exportExcel(list, "tCompanyDept");
    }
	
	/**
	 * 新增企业部门管理
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		 mmap.put("dept", tCompanyDeptService.selectDeptById());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存企业部门管理
	 */
	@RequiresPermissions("system:tCompanyDept:add")
	@Log(title = "企业部门管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TCompanyDept tCompanyDept)
	{		
		return toAjax(tCompanyDeptService.insertTCompanyDept(tCompanyDept));
	}

	/**
	 * 修改企业部门管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		TCompanyDept tCompanyDept = tCompanyDeptService.selectTCompanyDeptById(id);
		mmap.put("tCompanyDept", tCompanyDept);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存企业部门管理
	 */
	@RequiresPermissions("system:tCompanyDept:edit")
	@Log(title = "企业部门管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TCompanyDept tCompanyDept)
	{		
		return toAjax(tCompanyDeptService.updateTCompanyDept(tCompanyDept));
	}
	
	/**
	 * 删除企业部门管理
	 */
	@RequiresPermissions("system:tCompanyDept:remove")
	@Log(title = "企业部门管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tCompanyDeptService.deleteTCompanyDeptByIds(ids));
	}
	
	 /**
     * 选择部门树
     */
    @GetMapping("/selectDeptTree/")
    public String selectDeptTree(ModelMap mmap)
    {
        mmap.put("dept", tCompanyDeptService.selectDeptById());
        return prefix + "/tree";
    }
    
    
    /**
     * 加载部门列表树
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Map<String, Object>> treeData()
    {
        List<Map<String, Object>> tree = tCompanyDeptService.selectDeptTree(new TCompanyDept());
        return tree;
    }
	
}
